package com.googlecode.pacswitch.actions;

import java.nio.channels.AsynchronousSocketChannel;
import java.util.Collections;
import java.util.List;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;

import com.googlecode.pacswitch.ObjectFactory;
import com.googlecode.pacswitch.PString;
import com.googlecode.pacswitch.PacSwitch;

/**
 * @author Andrey Pavlenko
 */
@XmlType(name = "Redirect", namespace = ObjectFactory.ANS)
public class Redirect extends Response {
    private final List<Header> _defaultHeaders = Collections
            .singletonList(new Header("Location", ""));

    @XmlAttribute(required = true)
    public PString getLocation() {
        return _defaultHeaders.get(0).getValue();
    }

    public void setLocation(final PString location) {
        _defaultHeaders.get(0).setValue(location);
    }

    @Override
    protected List<Header> getDefaultHeaders() {
        return _defaultHeaders;
    }

    @Override
    protected int resolveStatusCode(final PacSwitch ps,
            final AsynchronousSocketChannel clientSocket) {
        return 303;
    }

    @Override
    protected String resolveReason(final PacSwitch ps,
            final AsynchronousSocketChannel clientSocket) {
        return "See Other";
    }
}
